package JZOffer;

//https://leetcode.cn/problems/fan-zhuan-dan-ci-shun-xu-lcof/?envType=study-plan&id=lcof&plan=lcof&plan_progress=xxj1ozje
// 翻转单词顺序
public class Day013_3 {
    public static String reverseWords(String s) {
        s = s.trim();
        String[] strings = s.split(" ");
        StringBuilder builder = new StringBuilder();

        for (int i = strings.length-1; i >= 0 ; i--) {
            if (!strings[i].equals("")) {
                builder.append(strings[i]);
                if (i != 0) {
                    builder.append(" ");
                }
            }
        }
        return builder.toString();
    }

    public static void main(String[] args) {
        String s = "a good   example";
        System.out.println(reverseWords(s));
    }
}
